package com.learn;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * org.springframwork.boot.autoconfigure.condition 包下有大量写好的注解类
 * @author Romanceling
 *
 */
@Configuration
public class TestConfig {

	@Bean
	@ConditionalOnProperty(name="runnable",//属性名
		havingValue="true",//当属性存在,值为true时
		matchIfMissing=true//属性不存在
	)
	public Runnable createRunnable(){
		return ()->{};
	}
	
	@Bean
	@ConditionalOnClass(name="com.google.gson.Gson")//当类存在时
	public Runnable createGsonRunnable(){
		return ()->{};	
	}
	
	@Bean
	@ConditionalOnBean(name="user")//当存在一个叫user的bean时
	//@ConditionalOnMissingBean(name="user")//当容器中不存在一个叫user的bean时
	public Runnable createUser(){
		return ()->{};	
	}
}
